/*
 * Filename AlgoClient.java 2021年09月26日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 * @author wuyingchao
 */
package com.ehome.poct.core.service.rpc;

import cn.hutool.core.lang.Tuple;
import com.ehome.feign.annotation.IgnoreFeignResponseAdvice;
import com.ehome.poct.core.api.dto.check.CellAlgoAnalysisDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.net.URI;

/**
 * 算法 rpc
 *
 * @author wyc
 * @since 2021/09/26 16:34
 **/
@Component
@RefreshScope
@RequiredArgsConstructor
public class CellAlgoRpcImpl implements CellAlgoRpc {
    private final AlgoClient algoClient;
    @Value("${algo.url}") private String algoUrl;

    /**
     * 算法分析
     *
     * @param dto
     * @return
     */
    @Override
    public Tuple analyse(@RequestBody CellAlgoAnalysisDTO dto) {
        final var analyse = algoClient.analyse(URI.create(algoUrl), dto);
        return new Tuple(algoUrl, analyse);
    }


    @FeignClient(value = "goldAlgo", contextId = "goldAlgo", url = "http://algo")
    interface AlgoClient {
        /**
         * 算法分析
         *
         * @param uri
         * @param dto
         * @return
         */
        @IgnoreFeignResponseAdvice
        @PostMapping("/process_ddd")
        String analyse(URI uri, @RequestBody CellAlgoAnalysisDTO dto);
    }
}